package com.yunquan.ohana.ui.calendar.event.month.adapter

import androidx.core.content.ContextCompat
import androidx.core.graphics.toColorInt
import androidx.databinding.ViewDataBinding
import com.yunquan.ohana.R
import com.yunquan.ohana.databinding.ItemEventMonthBinding
import com.yunquan.ohana.ui.calendar.event.month.EventMonthChildItemViewModel
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter

class EventMonthChildAdapter : BindingRecyclerViewAdapter<EventMonthChildItemViewModel>() {
    override fun onBindBinding(binding: ViewDataBinding, variableId: Int, layoutRes: Int, position: Int, item: EventMonthChildItemViewModel?) {
        super.onBindBinding(binding, variableId, layoutRes, position, item)
        if (binding is ItemEventMonthBinding) {
            // 设置背景色
            val roles = item?.data?.scheduleToRoleVos ?: mutableListOf()
            val firstRole = roles.first()
            if (roles.isNotEmpty()) {
                binding.vOut.helper.backgroundColorNormal = firstRole.getColorData().inner.toColorInt()
                binding.tvContent.helper.backgroundColorNormal = firstRole.getColorData().outer.toColorInt()
            }
        }
    }
}